package DD;


import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;

public class cc {
    public static void main(String[] args) throws IllegalAccessException, InstantiationException, NoSuchFieldException, NoSuchMethodException, InvocationTargetException {
        Class c= Human.class;
        Method[] declaredMethods = c.getDeclaredMethods();
        for (Method declaredMethod : declaredMethods) {
            System.out.println(declaredMethod);
            if (declaredMethod.getName().equals("test3" )){
                declaredMethod.setAccessible(true);
                Object o = c.newInstance();
                declaredMethod.invoke(o,22);
                System.out.println(o);
            }
        }
//        Constructor[] declaredConstructors = c.getDeclaredConstructors();
//        for (Constructor declaredConstructor : declaredConstructors) {
//            System.out.println(Arrays.toString(declaredConstructor.getParameterTypes()));
//
//        }


//        Constructor constructor = c.getDeclaredConstructor(String.class, int.class, double.class);
//        constructor.setAccessible(true);
//        System.out.println(constructor);
//        Object person = constructor.newInstance("aa", 2, 2.0);
//        System.out.println(person);

//        Human human= new Human();
//        a.setAccessible(true);
//        Object value=a.get(human);
//        a.set(human,22);
//        System.out.println(human);
//        Field a=c.getField("name");
//        Human h= new Human();
//        Object value = a.get(h);
//        System.out.println(value);
//        a.set(h,"小白");
//        System.out.println(h);
//        Field[]a=c.getDeclaredFields();
//        for (Field b:a
//             ) {
//            System.out.println(b.getName());
//            if (b.getName().equals("name")){
//                Object obj=c.newInstance();
//                b.set(obj,"小白");
//                System.out.println(b.get(obj));
//            }
//        }
    }
}